const defaultState = {
    loading: false,
    dataSource: [],
    visible: false,
    orgId: null,
    roles: []
};
export default function userList(state = defaultState, action) {
    const {type, payload, error} = action;
    switch (type) {
        case 'ORGANIZATION.SHOW_USERS':
            if (error === true) {
                return {...state, loading: false, visible: false};
            }
            return {
                ...state,
                loading: false,
                visible: true,
                orgId: payload,
                dataSource: []
            };
        case 'ORGANIZATION.HIDE_USERS':
            if (error === true) {
                return {...state, loading: false, visible: false};
            }
            return {
                ...state,
                loading: false,
                visible: false,
                dataSource: []
            };
        case 'ORGANIZATION.QUERY_USER':
            if (error === true) {
                return {...state, loading: false, visible: false};
            }
            return {
                ...state,
                loading: false,
                dataSource: payload
            };
        case 'ORGANIZATION.ROLES':
            if (error === true) {
                return {...state, loading: false, visible: false};
            }
            return {
                ...state, roles: [...payload]
            };
        default:
            return state;
    }
}

